﻿using System.ComponentModel;

namespace WITD
{
    /// <summary>
    /// 
    /// </summary>
    /// <typeparam name="T"></typeparam>
    public class CheckedListItem<T> : INotifyPropertyChanged
    {
        /// <summary>
        /// Provides a way to display a checkbox next to each item in a ListBox.
        /// </summary>
        public event PropertyChangedEventHandler PropertyChanged;
        private bool isChecked;
        private T item;

        /// <summary>
        /// Constructor
        /// </summary>
        public CheckedListItem() { }

        /// <summary>
        /// Constructor: accepts the item and its checked state.
        /// </summary>
        /// <param name="item">The item to display in the ListBox.</param>
        /// <param name="isChecked">The checked state of the item.</param>
        public CheckedListItem(T item, bool isChecked = false)
        {
            this.item = item;
            this.isChecked = isChecked;
        }

        /// <summary>
        /// Gets or sets the actual item instance.
        /// </summary>
        public T Item
        {
            get
            {
                return item;
            }

            set
            {
                item = value;
                if (PropertyChanged != null)
                    PropertyChanged(this, new PropertyChangedEventArgs("Item"));
            }
        }

        /// <summary>
        /// Gets or sets the checked state of the item.
        /// </summary>
        public bool IsChecked
        {
            get
            {
                return isChecked;
            }

            set
            {
                isChecked = value;
                if (PropertyChanged != null)
                    PropertyChanged(this, new PropertyChangedEventArgs("IsChecked"));
            }
        }
    } 
}
